package com.xand.bt.terminal.common.api;

import com.xand.bt.terminal.common.util.NumberHelper;

public class MarketDepthUpdate {
	
	public static final int UPDATE_TYPE_ADD_LEVEL 				= 0;
	public static final int UPDATE_TYPE_UPDATE_LEVEL_VOLUME 	= 1;
	public static final int UPDATE_TYPE_REMOVE_LEVEL 			= 2;
	
	public static final int DIRECTION_ASK 						= 0;
	public static final int DIRECTION_BID 						= 1;
	
	private int updateType;
	
	private String reference;
	
	// price is represented as entire number with 6 decimals, for example,
	// the representation of 11.499 would be 11499000
	private long price;
	
	// volume is represented as entire number with 8 decimals, for example,
	// the representation of 2.5281 would be 252810000
	private long volume;
	
	private int direction;
	
	public MarketDepthUpdate(
			int updateType, 
			String reference,
			int direction,
			long price, 
			long volume) {
		
		this.updateType = updateType;
		this.reference = reference;
		this.direction = direction;
		this.price = price;
		this.volume = volume;
		
	}

	public int getDirection() {
		return this.direction;
	}
	
	public int getUpdateType() {
		return updateType;
	}

	public String getReference() {
		return reference;
	}

	public long getPrice() {
		return price;
	}

	public long getVolume() {
		return volume;
	}
	
	public String getTextUpdateType() {
		
		String ret = "";
		
		switch(this.updateType) {
		
			case UPDATE_TYPE_ADD_LEVEL:
				ret = "ADD LEVEL";
				break;
				
			case UPDATE_TYPE_UPDATE_LEVEL_VOLUME:
				ret = "UPDATE VOLUME";
				break;
				
			case UPDATE_TYPE_REMOVE_LEVEL:
				ret = "REMOVE LEVEL";
				break;
		
		}
		
		return ret;
	}
	
	public String getTextDirection() {
		
		String ret = "";
		
		switch(this.direction) {
		
			case DIRECTION_ASK:
				ret = "ASK";
				break;
				
			case DIRECTION_BID:
				ret = "BID";
				break;
		
		}
		
		return ret;
	}
	
	public String toString() {
		
		StringBuilder ret = new StringBuilder();
		
		ret.append("MarketDepthUpdate - [");
		
		ret.append("updateType=");
		ret.append(this.getTextUpdateType());
		ret.append(";");
		
		ret.append("direction=");
		ret.append(this.getTextDirection());
		ret.append(";");
		
		ret.append("reference=");
		ret.append(reference);
		ret.append(";");
		
		ret.append("price=");
		ret.append(NumberHelper.formatLong(this.price, 1000000, 6));
		ret.append(";");
		
		ret.append("volume=");
		ret.append(NumberHelper.formatLong(this.volume, 100000000, 8));
		
		ret.append("]");
		
		return ret.toString();
		
	}
	
}
